package com.cxg.fairy.ec.detail;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.text.SpannableString;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.diabin.latte.ec.R;

import java.util.ArrayList;

/**
 * Created by CFairy
 */

public class CommentTabAdapter extends FragmentStatePagerAdapter {

    private int skuId = 0;

    private JSONArray array;

    public CommentTabAdapter(FragmentManager fm, JSONArray data,int mSkuId) {
        super(fm);
        skuId = mSkuId;
        array = data;
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return CommentListDelegate.create(0,skuId);
        } else if (position == 1) {
            return CommentListDelegate.create(1,skuId);
        } else if (position == 2) {
            return CommentListDelegate.create(2,skuId);
        } else if (position == 3) {
            return CommentListDelegate.create(3,skuId);
        }
        return null;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {

        String count = "0";
        String title= "";

        switch (position) {
            case 0:
                count = array.getJSONObject(0).getInteger("goodsEvalSum")+"";
                title = array.getJSONObject(0).getString("title");
                break;
            case 1:
                count = array.getJSONObject(1).getInteger("goodsEvalSum")+"";
                title = array.getJSONObject(1).getString("title");
                break;
            case 2:
                count = array.getJSONObject(2).getInteger("goodsEvalSum")+"";
                title = array.getJSONObject(2).getString("title");
                break;
            case 3:
                count = array.getJSONObject(3).getInteger("goodsEvalSum")+"";
                title = array.getJSONObject(3).getString("title");
                break;
            default:
                break;
        }

        SpannableString ss = new SpannableString("" + title+"\n"+count);

        return ss;
    }
}
